home *** CD-ROM | disk | FTP | other *** search
- /* copyb.c - copy a file with fscanf/fprintf */
- #include "stdio.h"
-
- main(argc,argv)
- int argc ;
- char *argv[] ;
- {
- FILE *in ,
- *out ;
- char c ;
- int nr ;
- long n ;
-
- if( argc < 3 )
- { printf(" USAGE - copy2 input-file output-file \n");
- exit(0) ;
- }
-
- in = fopen(argv[1],"r");
- out = fopen(argv[2],"w");
- if( ( in == NULL ) || ( out == NULL ) )
- { printf("Cant open a file");
- exit(0) ;
- }
-
- n = 0L ;
- nr = fscanf( in,"%c",c);
- while( nr > 0 )
- { n = n + 1 ;
- fprintf(out,"%c",c) ;
- nr = fscanf(in,"%c",&c) ;
- } ;
- fclose(in) ;
- fclose(out) ;
- printf(" %1d characters copied",n) ;
- }